<?php

class StatsController extends Zend_Controller_Action {

    public function init() {
        /* Initialize action controller here */
    }

    public function cumulVisiteurAction() {
        $db = Zend_Db_Table::getDefaultAdapter();
        $query = "select idVisiteur, mois, count(*) as nbFiches, sum(montantValide) as total
            from fichefrais
            group by idVisiteur, mois
            order by idVisiteur";
        $lesStats = $db->fetchAll($query);
        $this->view->lesStats = $lesStats;
    }

    public function cumulFraisAction() {
        $db = Zend_Db_Table::getDefaultAdapter();
        $query = "select idvisiteur, mois,
            SUM(case idfraisforfait when 'ETP' then quantite*montant end) as ETP,
            SUM(case idfraisforfait when 'KM' then quantite*montant end) as KM,
            SUM(case idfraisforfait when 'NUI' then quantite*montant end) as NUI,
            SUM(case idfraisforfait when 'REP' then quantite*montant end) as REP
            from fraisforfait ff, lignefraisforfait lff
            where lff.idfraisforfait = ff.id
            group by idvisiteur, mois
            order by idvisiteur, mois";
        $lesStats = $db->fetchAll($query);
        $this->view->lesStats = $lesStats;
    }

}

